package com.szrt.day20170418.ch06.dateformat;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.junit.Test;

public class SimpleDateFormatTest {
	
	
	@Test
	public void caled01() throws Exception {
		/*Calendar cc = new GregorianCalendar();
		System.out.println(cc);*/
		
		Calendar  cal = Calendar.getInstance() ;
		System.out.println(cal);
		
		
		
		//System.out.println(date.getYear());
		int aa =cal.getWeekYear();
		System.out.println(aa);
		
		cal.set(Calendar.YEAR,2018);
		cal.set(Calendar.DATE, 19);
		
		Date date  = cal.getTime();
		System.err.println(date);
		
		
	}
	
	@Test
	public void sdf02() throws Exception {
		
		String yd="2017-05-01";
		
		System.out.println(yd);
		
		String pattern1="yyyy-MM-dd";
		DateFormat format = new SimpleDateFormat(pattern1);
		
		//把1个字符串转化成日期  以后凡是通过http请求过来的数据都是字符串 51
		
		Date date51 =format.parse(yd);
		System.out.println(date51);
		
		//今天
		Date date = new Date();
		String jintian =format.format(date);
		System.out.println(jintian);
		
		long aa = date51.getTime()-format.parse(jintian).getTime();
		
		long aaa = aa/24/60/60/1000;
		System.out.println(aaa);
		
	}
	
	@Test
	public void sdf01() throws Exception {
		
		Date date = new Date();
		
		String pattern1="yyyy-MM-dd HH:mm:ss";
		DateFormat format = new SimpleDateFormat(pattern1);
		
		//把日期转化成指定格式的字符串
		String aa = format.format(date);
		System.err.println(aa);
	}

}
